#!/usr/bin/env python
# -*- coding: utf-8 -*-

from config import etc
from pymongo import MongoClient

client = MongoClient(etc.mongo_host)
# client = MongoClient(etc.mongo_host, etc.mongo_port)

db_shitouren = client.shitouren

# db_shitouren.counter


def create_seq_userid(start_num):
    if not db_shitouren.counter.find_one({'_id': etc.key_userseq}):
        db_shitouren.counter.save(
            {
                '_id': etc.key_userseq,
                'seq': start_num,
            }
        )


def create_seq_resetid(start_num):
    if not db_shitouren.counter.find_one({'_id': etc.key_resetseq}):
        db_shitouren.counter.save(
            {
                '_id': etc.key_resetseq,
                'seq': start_num,
            }
        )


def create_seq_labelid(start_num):
    if not db_shitouren.counter.find_one({'_id': etc.key_labelseq}):
        db_shitouren.counter.save(
            {
                '_id': etc.key_labelseq,
                'seq': start_num,
            }
        )


def create_seq_imgid(start_num):
    if not db_shitouren.counter.find_one({'_id': etc.key_imgseq}):
        db_shitouren.counter.save(
            {
                '_id': etc.key_imgseq,
                'seq': start_num,
            }
        )


def create_seq_topicid(start_num):
    if not db_shitouren.counter.find_one({'_id': etc.key_topicseq}):
        db_shitouren.counter.save(
            {
                '_id': etc.key_topicseq,
                'seq': start_num,
            }
        )


def create_seq_noteid(start_num):
    if not db_shitouren.counter.find_one({'_id': etc.key_noteseq}):
        db_shitouren.counter.save(
            {
                '_id': etc.key_noteseq,
                'seq': start_num,
            }
        )

def create_seq_messageid(start_num):
    if not db_shitouren.counter.find_one({'_id': etc.key_messageseq}):
        db_shitouren.counter.save(
            {
                '_id': etc.key_messageseq,
                'seq': start_num,
            }
        )


def count_userid():
    ret = db_shitouren.counter.find_and_modify(
        query={'_id': etc.key_userseq},
        update={'$inc': {'seq': 1}},
    )
    return ret['seq']


def count_resetid():
    ret = db_shitouren.counter.find_and_modify(
        query={'_id': etc.key_resetseq},
        update={'$inc': {'seq': 1}},
    )
    return ret['seq']


def count_labelid():
    ret = db_shitouren.counter.find_and_modify(
        query={'_id': etc.key_labelseq},
        update={'$inc': {'seq': 1}},
    )
    return ret['seq']


def count_imgid():
    ret = db_shitouren.counter.find_and_modify(
        query={'_id': etc.key_imgseq},
        update={'$inc': {'seq': 1}},
    )
    return ret['seq']


def count_topicid():
    ret = db_shitouren.counter.find_and_modify(
        query={'_id': etc.key_topicseq},
        update={'$inc': {'seq': 1}},
    )
    return ret['seq']


def count_noteid():
    ret = db_shitouren.counter.find_and_modify(
        query={'_id': etc.key_noteseq},
        update={'$inc': {'seq': 1}},
    )
    return ret['seq']

def count_messageid():
    ret = db_shitouren.counter.find_and_modify(
        query={'_id': etc.key_message},
        update={'$inc': {'seq': 1}},
    )
    return ret['seq']


if __name__ == "__main__":
    print 'main start'